home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / editors / CED / rexx / DICEHelp.ced < prev    next >
Encoding:
Text File  |  1994-02-01  |  3.8 KB  |  180 lines

  1. /*
  2.  * DICEHelp.ced - Invoke DICEHelp from within 
  3.  *                CygnusEd Professional Release 2
  4.  * 
  5.  * Written for DICE by Peter Cherna.  (c) Copyright 1992, Peter Cherna
  6.  *     Used with permission.
  7.  *
  8.  * Usage:
  9.  *    DICEHelp.ced    - Get help on the word under the cursor
  10.  *    DICEHelp.ced ?   - Request string to get help on
  11.  *    DICEHelp.ced arg - Get help on the word "arg"
  12.  *
  13.  * You will probably want to bind "DICEHelp.ced" and "DICEHelp.ced ?"
  14.  * to function keys.  Use the menu "Special" then "DOS/AREXX Interface".
  15.  */
  16.  
  17. options results
  18.  
  19. /* If the argument is a question mark, request a string from the user */
  20. if arg(1) = "?" then
  21. do
  22.     /* CED doesn't let us provide a NULL string for
  23.      * the default contents of the string requester,
  24.      * so we provide a space and worry about it later
  25.      */
  26.     "getstring ' ' 'DICEHelp: Enter search string'"
  27.     target = result
  28.     /* Remove a trailing space, if any */
  29.     if ((target ~= "") & (right(target,1) = " ")) then
  30.         target = left(target, length(target)-1)
  31. end
  32. /* If there is any other argument, use that */
  33. else if (arg() > 0) then
  34. do
  35.     target = arg(1)
  36. end
  37. else /* Get the word under the cursor */
  38. do
  39.     /* Get contents of current line: */
  40.     "status 55"    /* linebuffer */
  41.     line = result
  42.  
  43.     /* Get cursor position. */
  44.     status 87 /* cursormemoryx */
  45.     cur = result + 1
  46.  
  47.     /* If the current character is non-alphabetic, then start one
  48.      * character over to the left.  This allows the cursor to be
  49.      * immediately after the key word (say on a space or bracket).
  50.      */
  51.     char = substr(line,cur,1)
  52.     if (~(datatype(char,"A") | char = "_") & cur > 1) then
  53.         cur = cur - 1
  54.  
  55.     /* Find leftmost and rightmost alphabetic character
  56.      * adjacent to current:
  57.      */
  58.     right = cur - 1
  59.     left = cur + 1
  60.     char = "A"
  61.     do while (datatype(char,"A") | char = "_") & (left > 0)
  62.          left = left - 1
  63.         if left > 0 then
  64.             char = substr(line,left,1)
  65.     end
  66.     char = "A"
  67.     do while (datatype(char,"A") | (char = "_"))
  68.         right = right + 1
  69.         char = substr(line,right,1)
  70.     end
  71.  
  72.     if (right-left <= 1) then
  73.     do
  74.         "okay1 DICEHelp: Cursor must be on a word."
  75.         exit
  76.     end
  77.     else
  78.     do
  79.         target = substr(line,left+1,right-left-1)
  80.     end
  81. end
  82.  
  83. if (target = "RESULT" | target = "") then
  84.     exit
  85.  
  86. if ~show("p","DICEHELP") then
  87. do
  88.     address command "run >NIL: <NIL: DICEHelp REXXSTARTUP"
  89.  
  90.     do i = 1 to 6
  91.         if ~show("p","DICEHELP") then
  92.         do
  93.             address COMMAND "wait 1"
  94.         end
  95.     end
  96.  
  97.     if ~show("p","DICEHELP") then
  98.     do
  99.         "okay1 DICEHelp: Program not found!"
  100.             exit
  101.     end
  102. end
  103.  
  104. /* Search for string, return <T>empfile */
  105. address "DICEHELP" "T" target
  106. filename = result
  107. if RC=0 then
  108. do
  109.     /* Temporarily turn off "auto-expand views" if on */
  110.     "status 72"
  111.     aev = result
  112.     if (aev = 1) then
  113.         "auto-expand views"
  114.  
  115.     /* If we have a help file displayed, use its window,
  116.      * else open a new one:
  117.      */
  118.     helpfile = getclip("HelpView")
  119.     /* Get name of current file */
  120.     "status 19"
  121.     if helpfile ~= result then
  122.     do
  123.         /* Find out how many views are displayed */
  124.         "status 66"
  125.  
  126.         /* Try to find the view containing the help file */
  127.         do numwins=result-1 to 1 by -1 until result = helpfile
  128.             "next view"
  129.             /* Get name of current file */
  130.             "status 19"
  131.         end
  132.     end
  133.  
  134.     if result ~= helpfile then
  135.     do
  136.     /* We can't find the HelpView, so make a new view: */
  137.         "next view"        /* bring back to original view */
  138.         "open new"
  139.     end
  140.     else
  141.     do
  142.         /* Number of changes in HelpView: */
  143.         "status 18"
  144.         if result ~= 0 then
  145.         do
  146.             /* HelpView has changes, so make a new view */
  147.             "next view"
  148.             "open new"
  149.         end
  150.     end
  151.  
  152.     /* Restore "auto-expand views" */
  153.     if (aev = 1) then
  154.         "auto-expand views"
  155.  
  156.     /* Load the file, and make it non-editable */
  157.     "open" filename 1
  158.     "status 82"
  159.     canedit = result
  160.  
  161.     if (canedit ~= 0) then
  162.         "editable file"
  163.  
  164.     /* Save file name of the Help View */
  165.     "status 19"
  166.     call setclip "HelpView",result
  167.  
  168. end
  169. else 
  170. if RC=1 then
  171. do
  172.     "okay1 DICEHelp: Couldn't find" '"'target'"'
  173. end
  174. else
  175. do
  176.     "okay1 DICEHelp: Failed, error code" RC
  177. end
  178.  
  179. exit
  180.